<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>


<title>POS收单运营管理平台</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link href="<s:url value="/css/common.less"/>" type="text/less"
	rel="stylesheet" />
	<link href="<s:url value="/css/common.css"/>" type="text/css"
	rel="stylesheet" />

<script type="text/javascript"
	src="<s:url value="/js/jquery-1.3.2.js" />"></script>
<script type="text/javascript"
	src="<s:url value="/js/jquery-1.9.1.js" />"></script>
<script type="text/javascript"
	src="<s:url value="/js/jquery.blockUI.js" />"></script>
<script type="text/javascript"
	src="<s:url value="/js/jquery.validate.min.js" />"></script>
<script type="text/javascript"
	src="<s:url value="/js/pwms.validate.js?v13" />"></script>
<script language="javascript" type="text/javascript"
	src="<s:url value="/js/My97DatePicker/WdatePicker.js"/>"></script>

<style type="text/css">

.error {
	color: red;
}

</style>
<script type="text/javascript">

	$(document).ready(function() {
		
		//检查是什么状态，更新或新增
		var flag="${flag}";
		if(flag=="update"){
			$("#riskForm").attr("action","<%=basePath%>/translimit/saveNewRiskRule.ct");
			typeChange("${bean.unite}");
		}

		// 字符最大长度验证（一个中文字符长度为2）
		jQuery.validator.addMethod("stringMaxLength", function(value,element, param) {
			var length = value.length;
			for ( var i = 0; i < value.length; i++) {
				if (value.charCodeAt(i) > 127) {
					length++;
				}
			}
			return this.optional(element) || (length <=param);
		}, $.validator.format("长度不能大于{0}!"));
		
		jQuery.validator.addMethod("isMoney", function(value,element) {
			var reg= /^([1-9][\d]{0,9}|0)(\.[\d]{1,2})?$/;
			if(reg.test(value)){
				return this.optional(element) || true;
			}
			return this.optional(element) || false;
			}, "");
		$("#riskForm").validate({
			debug : true,
			submitHandler : function(form) {
				$("#btnAdd").attr("disabled",true);
					form.submit();
			},
			rules : {
				"bean.transType" : {required : true},				 
				"bean.riskInfo" : {required : true},
				"bean.riskCycle" : {required : true},
				"bean.riskKey" : {required : true},
				"bean.riskMethod" : {required : true},
				"bean.unite" : {required : true},
				"bean.status" : {required : true},
				"bean.mchtCd" : {required : true},
				"bean.termCd" : {required : true},
				"bean.valueMax" : {required : true,isMoney:true}																					
			},
			messages : {
				"bean.transType" : {required : "必填"},				 
				"bean.riskInfo" : {required : "必填"},
				"bean.riskCycle" : {required : "必填"},
				"bean.riskKey" : {required : "必填"},
				"bean.riskMethod" : {required : "必填"},
				"bean.unite" : {required : "必填"},
				"bean.status" : {required : "必选"},
				"bean.mchtCd" : {required : "必填，可用*代替通用商户号"},
				"bean.termCd" : {required : "必填，可用*代替通用终端号"},
				"bean.valueMax" : {required : "必填",isMoney:"必须在0-9999999999.99之间，最多{2}位小数"},
			},errorPlacement: function(error, element) { 
			    if ( element.is(":radio") ) 
			        error.appendTo ( element.parent() ); 
			    else if ( element.is(":checkbox") ) 
			        error.appendTo ( element.parent() ); 
			    else if ( element.is("input") ) {
			    	error.appendTo ( element.parent() ); 
			    }
			    else 
			        error.insertAfter(element); 
			} 

		});
		
		$('#unite').change(function(){
			typeChange($("#unite").val());
		});
	});
	function typeChange(type)
	{		
		if(type=="Money"){
			$("#maxValue").text("最大金额：");
		}else if(type=="Count"){
			$("#maxValue").text("最大次数：");
		}else if(type=="Time"){
			$("#maxValue").text("最长时间间隔：");
		}
	}
</script>



</head>

<body>
			<s:form id="riskForm" action="/translimit/addRule.ct" method="post"  theme="simple"  >
				<table width="100%" class="tb" >
			        <tr class="tb-line">
			            <td class="tb-td" colspan="4">
				            <div class="tb-h2">POS收单运营管理平台</div>
					   	</td>
			        </tr>
	                <tr class="tb-line bg-gray">
			            <td class="tb-td" colspan="4"><div class="tb-h3"><s:if test="#request.flag ==\"update\"">
			                	修改风控规则<s:if test="bean.inCd == \"*\" ">(规则模板)</s:if>
			                	</s:if>
			                	<s:else>
			                	添加风控规则
			                	</s:else></div></td>
			        </tr>
					<tr class="tb-line">						
					     <td align="right" class="tb-td" style="width:110px;">
				        	<div class="tb-h4">所属机构：</div>
			            </td>
			            <td class="tb-td" >
			             	
			             		<s:if test="#request.flag ==\"update\" ">
			             		<s:if test="bean.inCd == \"*\" ">
			             			<s:property value="bean.inCd"/>
			             		</s:if>
								<s:else>
								<s:select cssClass="queryWidth" name="bean.inCd" id="orgCode"
								list="#request.orgList" listKey="insIdCd" listValue="insName" disabled="true"/>
								</s:else>
								<s:hidden name="bean.inCd"></s:hidden>
								</s:if>
								<s:else>
								<label class="tb-select">
								<s:select cssClass="queryWidth" name="bean.inCd" id="orgCode"
								list="#request.orgList" listKey="insIdCd" listValue="insName"/>
								
						 	</label>
						 	<font color="red">*</font>
						 	</s:else>
						</td>
				    	<td width="12%" style="min-width: 150px" align="right" class="tb-td">
				 	 <div class="tb-h4">交易类型：</div>
				 	 </td>
					<td class="tb-td">
                	<s:if test="#request.flag ==\"update\" ">
                	<s:select name="bean.transType" list="#{'POS_D0':'D0','POS_T1':'T1','POS_T1+D0':'T1+D0'}" headerKey="" headerValue="请选择" cssClass="queryWidth"  disabled="true"/>
					<s:hidden name="bean.transType"></s:hidden>
                	</s:if>
					<s:else>
					<label class="tb-select">
					<s:select name="bean.transType" list="#{'POS_D0':'D0','POS_T1':'T1','POS_T1+D0':'T1+D0'}" headerKey="" headerValue="请选择" cssClass="queryWidth" /> 
					</label>
					<font color="red">*</font>
					</s:else>				
					</td>
					</tr>
					<tr class="tb-line">						
					     <td align="right" class="tb-td" style="width:110px;">
				        	<div class="tb-h4">风控对象：</div>
			            </td>
			            <td class="tb-td" >
						 	<s:if test="#request.flag ==\"update\" ">
			             		<s:select name="bean.riskInfo" list="#{'Mcht':'商户','Card':'银行卡'}" headerKey="" headerValue="请选择" cssClass="queryWidth" disabled="true"/> 
								<s:hidden name="bean.riskInfo"></s:hidden>							
								</s:if>
								<s:else>
								<label class="tb-select">
								<s:select name="bean.riskInfo" list="#{'Mcht':'商户','Card':'银行卡'}" headerKey="" headerValue="请选择" cssClass="queryWidth" /> 
								</label>
								<font color="red">*</font>
								</s:else>
						</td>
				    	<td width="12%" style="min-width: 150px" align="right" class="tb-td">
				 	 <div class="tb-h4">风控周期：</div>
				 	 </td>
					<td class="tb-td">
					<s:if test="#request.flag ==\"update\" ">
			             		<s:select name="bean.riskCycle" list="#{'Normal':'通用','Month':'单月','Day':'单日'}" headerKey="" headerValue="请选择" cssClass="queryWidth" disabled="true"/> 
								<s:hidden name="bean.riskCycle"></s:hidden>							
								</s:if>
								<s:else>
                				<label class="tb-select">               	
								<s:select name="bean.riskCycle" list="#{'Normal':'通用','Month':'单月','Day':'单日'}" headerKey="" headerValue="请选择" cssClass="queryWidth" /> 
								</label>
								<font color="red">*</font>
								</s:else>
					</td>
					</tr>
					<tr class="tb-line">						
					     <td align="right" class="tb-td" style="width:110px;">
				        	<div class="tb-h4">特使类型：</div>
			            </td>
			            <td class="tb-td" >
			            	<s:if test="#request.flag ==\"update\" ">
			            	<s:select name="bean.riskKey" list="#{'CT':'磁条卡','IC':'芯片卡','Credit':'贷记卡','Debit':'借记卡','Normal':'通用','Min':'最小值','Max':'最大值','Mcht':'单商户'}" headerKey="" headerValue="请选择" cssClass="queryWidth" disabled="true"/>
							<s:hidden name="bean.riskKey"></s:hidden>
			            	</s:if>
			            	<s:else>
			             	<label class="tb-select">
								<s:select name="bean.riskKey" list="#{'CT':'磁条卡','IC':'芯片卡','Credit':'贷记卡','Debit':'借记卡','Normal':'通用','Min':'最小值','Max':'最大值','Mcht':'单商户'}" headerKey="" headerValue="请选择" cssClass="queryWidth" />
						 	</label>
						 	<font color="red">*</font>
						 	</s:else>
						</td>
				    	<td width="12%" style="min-width: 150px" align="right" class="tb-td">
				 	 <div class="tb-h4">计算方法：</div>
				 	 </td>
					<td class="tb-td">
					<s:if test="#request.flag ==\"update\" ">
					<s:select name="bean.riskMethod" list="#{'Total':'累计','Single':'单笔'}" headerKey="" headerValue="请选择" cssClass="queryWidth" disabled="true"/> 
					<s:hidden name="bean.riskMethod"></s:hidden>
					</s:if>
					<s:else>
                	<label class="tb-select">
						<s:select name="bean.riskMethod" list="#{'Total':'累计','Single':'单笔'}" headerKey="" headerValue="请选择" cssClass="queryWidth" /> 
					</label>
					<font color="red">*</font>
					</s:else>
					</td>
					</tr>
					<tr class="tb-line">						
					     <td align="right" class="tb-td" style="width:110px;">
				        	<div class="tb-h4">单位：</div>
			            </td>
			            <td class="tb-td" >
			            <s:if test="#request.flag ==\"update\" ">
			            <s:select name="bean.unite" list="#{'Money':'金额','Count':'次数','Time':'间隔时间(s)'}" headerKey="" headerValue="请选择" cssClass="queryWidth" disabled="true"/>
							<s:hidden name="bean.unite"></s:hidden>
			            </s:if>
			            <s:else>
			             	<label class="tb-select">
								<s:select name="bean.unite" list="#{'Money':'金额','Count':'次数','Time':'间隔时间(s)'}" headerKey="" headerValue="请选择" cssClass="queryWidth" id="unite"/>
						 	</label>
						 	<font color="red">*</font>
						 	</s:else>
						</td>
				    	<td align="right" class="tb-td" style="width:110px;">
				        		<div class="tb-h4">状态：</div>
			            </td>
			            <td class="tb-td" >
			             		<s:radio name="bean.status" list="#{'1':'启用','0':'关闭' }"></s:radio><font color="red">*</font>
						 </td>
					</tr>
						<tr class="tb-line">
						<td align="right" class="tb-td">
				        	<div class="tb-h4">商户号：</div>
			            </td>
			            <td class="tb-td" >			             	
								<s:if test="#request.flag ==\"update\" ">
								<label class="tb-input-lengthen">
								<s:textfield maxLength="200" theme="simple" cssClass="queryWidth" disabled="true" value="%{bean.mchtCd}"></s:textfield>	
								</label>
								<s:hidden name="bean.mchtCd"></s:hidden>
								</s:if>
								<s:else>
								<label class="tb-input-lengthen">
			             		<s:textfield maxLength="200" name="bean.mchtCd"
									cssClass="queryWidth" id="mchtCd"></s:textfield>
								</label>
								</s:else>
								<font color="red">*</font>
						</td>
						<td align="right" class="tb-td">
				        	<div class="tb-h4">终端号：</div>
			            </td>
			            <td class="tb-td" >			             	
								<s:if test="#request.flag ==\"update\" ">
								<label class="tb-input-lengthen">
								<s:textfield maxLength="200" theme="simple" cssClass="queryWidth" disabled="true" value="%{bean.termCd}"></s:textfield>	
								</label>
								<s:hidden name="bean.termCd"></s:hidden>
								</s:if>
								<s:else>
								<label class="tb-input-lengthen">
			             		<s:textfield maxLength="200" name="bean.termCd"
									cssClass="queryWidth" id="termCd"></s:textfield>
								</label>
								</s:else>
								<font color="red">*</font>
						</td>
						</tr>
						
						<tr class="tb-line">					
				    	<td align="right" class="tb-td">
				        	<div class="tb-h4" id="maxValue">最大金额：</div>
			            </td>
			            <td class="tb-td" >			             	
								<label class="tb-input-lengthen">
			             		<s:textfield maxLength="200" name="bean.valueMax"
									cssClass="queryWidth" id="mchtCd"></s:textfield>
								</label>
								<font color="red">*</font>
						</td>
						</tr>				   
						
				</table>		
		      <table width="100%" border="0" cellspacing="0" class="table">
		           	<tr class="tb-line">
						<td colspan="4" align="center"><span style="color: red"><s:actionerror /></span>
							<span style="color: red;"><s:actionmessage /></span > <span style="color: red;"><s:fielderror
									cssClass="fieldError" /></span>
							<span id="otherError"></span>
						</td>
					</tr>
					<tr class="tb-line">
			            <td class="tb-td line-submit" align="center" colspan="4">
			                <label class="tb-input-submit">		                
			                	<s:submit id="btnAdd" value="保  存" />								
							</label>
			                <label class="tb-input-submit">
								<input type="reset" value="取  消"/>
							</label>
							<label class="tb-input-submit">
								<input type="button" value="返回" onclick="history.back()"/>
							</label>
						</td>
					</tr>
            </table>
			</s:form>	
</body>
</html>
